//
//  LYLoanGuideView.swift
//  LYOnlineBanking
//
//  Created by 李永彬 on 2025/7/22.
//

import UIKit

class LYLoanGuideView: UIView {
    
    lazy var bgImageView: UIImageView = {
        let imageView = UIImageView()
        if appCountryEnv == .indonesia {
            imageView.image = UIImage(named: "loan_guide_1_id")
        } else {
            imageView.image = UIImage(named: "loan_guide_1")
        }
        imageView.contentMode = .scaleAspectFill
        return imageView
    }()
    
    lazy var button1: UIButton = {
        let button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(firstButtonAction(_:)), for: .touchUpInside)
        return button
    }()
    
    lazy var button2: UIButton = {
        let button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(secondButtonAction(_:)), for: .touchUpInside)
        return button
    }()
    
    lazy var button3: UIButton = {
        let button = UIButton(type: .custom)
        button.addTarget(self, action: #selector(thirdButtonAction(_:)), for: .touchUpInside)
        return button
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(bgImageView)
        bgImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        // Add buttons to the view
        addSubview(button1)
        addSubview(button2)
        addSubview(button3)
        
        // Set up constraints for equal horizontal distribution
        button1.snp.makeConstraints { make in
            make.leading.equalToSuperview()
            make.top.equalToSuperview().offset(80)
            make.width.equalTo(button2)
            make.width.equalTo(button3)
        }
        
        button2.snp.makeConstraints { make in
            make.leading.equalTo(button1.snp.trailing)
            make.top.equalTo(button1)
            make.width.equalTo(button1)
        }
        
        button3.snp.makeConstraints { make in
            make.leading.equalTo(button2.snp.trailing)
            make.top.equalTo(button1)
            make.trailing.equalToSuperview()
            make.width.equalTo(button1)
        }
        
        // Make all buttons the same height (adjust as needed)
        [button1, button2, button3].forEach { button in
            button.snp.makeConstraints { make in
                make.height.equalTo(50) // Set your desired height
            }
        }
    }
    
    @objc func firstButtonAction(_ button: UIButton) {
        bgImageView.image = UIImage(named: "loan_guide_1")
    }
    
    @objc func secondButtonAction(_ button: UIButton) {
        bgImageView.image = UIImage(named: "loan_guide_2")
    }
    
    @objc func thirdButtonAction(_ button: UIButton) {
        bgImageView.image = UIImage(named: "loan_guide_3")
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
